home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12961 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: columba.udac.uu.se!not-for-mail
  2. From: trulsson@student.docs.uu.se (Erik Trulsson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How can I use huge || very small number?
  5. Date: 3 Apr 1996 17:46:34 GMT
  6. Organization: Uppsala Universitet
  7. Message-ID: <4judhq$1vf6@columba.udac.uu.se>
  8. References: <315681F3.314D@blue.nowcom.co.kr> <4joh0l$jch@news.acns.nwu.edu> <4jpep5$db2@penage.cs.laurentian.ca>
  9. NNTP-Posting-Host: minsk.docs.uu.se
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Edward C. Chan (echan@nickel.laurentian.ca) wrote:
  13. > >>may be it is FAQ but...
  14. > >>how can I compute 10000! or 0.12345......
  15. > >
  16. > >10000! is a very, very big number.
  17. > >I'm not sure it's even representable by standard IEEE fp notation.
  18. > >Any have that formula? 2*pi*e something or another.
  19. > I don't think 10000! will fit a long double.  So why not store it on
  20. > an array (or a linked list) of longs?
  21.  
  22. It won't fit into any standard data type. What you will have to do is
  23. to represent the numbers as strings of digits and do all the operations
  24. yourself. (Very much like you do when calculating on paper.)
  25. This approach is a lot slower than using the builtin data types but
  26. you can use arbitrarily large numbers.
  27.  
  28. > As for small numbers, most commercially-available compilers are cacable
  29. > of near-infinite precision when optimized (i.e. no debugging info.)  As
  30. > far as I know, Watcom has the highest floating-point precision.  Again, the
  31. > same principle I described above will also help.
  32.  
  33. If you use the standard data types (i.e. float or double) and your system uses
  34. the IEEE standard for floating point (which most systems do these days)
  35. the there are limits.
  36. A single precision number (float) has about seven digits of precision and the 
  37. smallest representable number is about 1E-38, for a double the values are
  38. 15 digits and 1E-308 instead.
  39. If you want better precision you will have to do it on your own in a similar
  40. way as for big numbers.
  41.  
  42.